package com.tensquare.base.service;

import com.tensquare.entity.PageResult;
import com.tensquare.util.IdWork;
import com.tensquare.base.dao.LabelDao;
import com.tensquare.base.pojo.Label;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class LabelService {

    @Autowired
    private LabelDao labelDao;

    @Autowired
    private IdWork idWork;

    public List<Label> findAll(int page, int limit){
        PageResult pageResult = new PageResult();
        pageResult.setCurrentPage(page);
        pageResult.setLimit(limit);
        pageResult.setStart(pageResult.computerStart());
        return labelDao.findAll(pageResult);
    }

    public Label findById(String id){

        return labelDao.findById(id);
    }

    public void add(Label label){
        label.setId(idWork.nextId());
//        labelDao.save(label);
        labelDao.add(label);
    }


    public void update(Label label){

//        labelDao.save(label);
        labelDao.update(label);
    }

    public void deleteById(String id){
//        labelDao.delete(id);
        labelDao.delete(id);
    }
}
